/*
 * config.cpp
 *
 *  Created on: 12.04.2014
 *      Author: Ralph
 */

#include "config.h"

#include <QDebug>
#include <QFile>

Config::Config()
{
}

Config::~Config()
{
}

bool Config::init()
{
    return loadFromFile();
}

bool Config::loadFromFile()
{
    QFile configFile( "config.cfg" );
    if ( !configFile.open( QIODevice::ReadOnly ) )
    {
        qDebug( "config file unreadable" );
        return false;
    }
    QTextStream ts( &configFile );
    QString nl;

    while ( !ts.atEnd() )
    {
        nl = ts.readLine();
        //For commenting out stuff in the setfiles
        if ( !nl.startsWith( "#" ) )
        {
            QStringList sl = nl.split( " " );
            if( sl.size() > 1 )
            {
                m_settings[sl[0]].setValue( sl[1] );
            }
        }
    }

    return true;
}

QVariant Config::get( QString key )
{
    if ( m_settings.contains( key ) )
    {
        return m_settings[key];
    }
    else
    {
        return QVariant();
    }
}
